package com.gfxy.modules.statistics.service;

import com.alibaba.fastjson.JSONObject;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CoreTotalScoreExcel {

    public void createSheet(Workbook workbook ,Sheet sheet,  String title, List<JSONObject> contents){


        CellStyle style = workbook.createCellStyle();
        style.setBorderTop(BorderStyle.THIN);
        style.setBorderBottom(BorderStyle.THIN);
        style.setBorderLeft(BorderStyle.THIN);
        style.setBorderRight(BorderStyle.THIN);

        CellStyle cellstyle2 = workbook.createCellStyle();
        cellstyle2.setVerticalAlignment(VerticalAlignment.CENTER);
        cellstyle2.setAlignment(HorizontalAlignment.CENTER);
        cellstyle2.setBorderTop(BorderStyle.THIN);
        cellstyle2.setBorderBottom(BorderStyle.THIN);
        cellstyle2.setBorderLeft(BorderStyle.THIN);
        cellstyle2.setBorderRight(BorderStyle.THIN);




        for(int i=0 ; i<=1; i++){
            Row row = sheet.createRow(i);
            for(int j = 0 ; j <= 11 ;j ++){
                Cell cell = row.createCell(j);
                cell.setCellValue(title);
                cell.setCellStyle(cellstyle2);
            }
        }
        CellRangeAddress region0 = new CellRangeAddress(0, 1, 0, 11);
        sheet.addMergedRegion(region0);


        this.createSubTitle(sheet, style);

        int rowIndex = 3;
        for (int i = 0; i < contents.size(); i++) {

            JSONObject content = contents.get(i);

            Row contentRow = sheet.createRow(rowIndex);

            Cell numCell = contentRow.createCell(0);
            numCell.setCellValue(i+1);
            numCell.setCellStyle(style);

            String teacherId = content.getString("teacherId");
            Cell teacherIdCell = contentRow.createCell(1);
            teacherIdCell.setCellValue(teacherId);
            teacherIdCell.setCellStyle(style);

            String realname = content.getString("realname");
            Cell realnameCell = contentRow.createCell(2);
            realnameCell.setCellValue(realname);
            realnameCell.setCellStyle(style);

            String titleRank = content.getString("titleRank_dictText");
            Cell titleRankCell = contentRow.createCell(3);
            titleRankCell.setCellValue(titleRank);
            titleRankCell.setCellStyle(style);

            String teacherType = content.getString("teacherType_dictText");
            Cell teacherTypeCell = contentRow.createCell(4);
            teacherTypeCell.setCellValue(teacherType);
            teacherTypeCell.setCellStyle(style);


            String orgName = content.getString("orgCode_dictText");
            Cell orgNameCell = contentRow.createCell(5);
            orgNameCell.setCellValue(orgName);
            orgNameCell.setCellStyle(style);

            String teachingOrgName = content.getString("teachingOrgCode_dictText");
            Cell teachingOrgNameCell = contentRow.createCell(6);
            teachingOrgNameCell.setCellValue(teachingOrgName);
            teachingOrgNameCell.setCellStyle(style);

            double teachingBuild = content.getDouble("teachingBuild");
            Cell teachingBuildCell = contentRow.createCell(7);
            teachingBuildCell.setCellValue(teachingBuild);
            teachingBuildCell.setCellStyle(style);

            double studentMatch = content.getDouble("studentMatch");
            Cell studentMatchCell = contentRow.createCell(8);
            studentMatchCell.setCellValue(studentMatch);
            studentMatchCell.setCellStyle(style);

            double research = content.getDouble("research");
            Cell researchCell = contentRow.createCell(9);
            researchCell.setCellValue(research);
            researchCell.setCellStyle(style);

            double studentManage = content.getDouble("studentManage");
            Cell studentManageCell = contentRow.createCell(10);
            studentManageCell.setCellValue(studentManage);
            studentManageCell.setCellStyle(style);

            double totalScore = content.getDouble("totalScore");
            Cell totalScoreCell = contentRow.createCell(11);
            totalScoreCell.setCellValue(totalScore);
            totalScoreCell.setCellStyle(style);
            rowIndex = rowIndex+1;

        }
    }
    private void createSubTitle(Sheet sheet, CellStyle style) {
        Row rowSubTitle2 = sheet.createRow(2);

        Cell num = rowSubTitle2.createCell(0);
        num.setCellValue("序号");
        num.setCellStyle(style);

        Cell teacherIdPointCell = rowSubTitle2.createCell(1);
        teacherIdPointCell.setCellValue("工号");
        teacherIdPointCell.setCellStyle(style);

        Cell classTimePointCell = rowSubTitle2.createCell(2);
        classTimePointCell.setCellValue("教师姓名");
        classTimePointCell.setCellStyle(style);

        Cell classTimeScoreCell = rowSubTitle2.createCell(3);
        classTimeScoreCell.setCellValue("职称");
        classTimeScoreCell.setCellStyle(style);

        Cell teacherTypeCell = rowSubTitle2.createCell(4);
        teacherTypeCell.setCellValue("教师类型");
        teacherTypeCell.setCellStyle(style);

        Cell classTimeBuildPointCell = rowSubTitle2.createCell(5);
        classTimeBuildPointCell.setCellValue("工作部门");
        classTimeBuildPointCell.setCellStyle(style);



        Cell teachingBuildScoreCell = rowSubTitle2.createCell(6);
        teachingBuildScoreCell.setCellValue("兼课学院");
        teachingBuildScoreCell.setCellStyle(style);


        Cell honourScoreCell = rowSubTitle2.createCell(7);
        honourScoreCell.setCellValue("教学建设");
        honourScoreCell.setCellStyle(style);

        Cell researchPointCell = rowSubTitle2.createCell(8);
        researchPointCell.setCellValue("学生大赛");
        researchPointCell.setCellStyle(style);


        Cell researchScoreCell = rowSubTitle2.createCell(9);
        researchScoreCell.setCellValue("科学研究与社会服务");
        researchScoreCell.setCellStyle(style);

        Cell educationPointCell = rowSubTitle2.createCell(10);
        educationPointCell.setCellValue("基层党建与学生管理");
        educationPointCell.setCellStyle(style);

        Cell educationScoreCell = rowSubTitle2.createCell(11);
        educationScoreCell.setCellValue("总分");
        educationScoreCell.setCellStyle(style);

    }
}
